Chris Pollett > Old Classes >
CS156

( Print View )

Student Corner:
  [Grades Sec1]
 
  [Submit Sec1]
 
  [
Lecture Notes]

Course Info:
  [Texts & Links]
  [Topics]
  [Grading]
  [HW Info]
  [Exam Info]
  [Regrades]
  [Honesty]
  [Announcements]

HW Assignments:
  [Hw1]  [Hw2]  [Hw3]
  [Hw4]

Practice Exams:
  [Mid1]  [Mid2]  [Final]

                           












HW#4 --- last modified March 02 2019 17:19:48..

Solution set.

Due date: May 17

Files to be submitted:
  Hw4.java

Purpose: To gain familiarity with probability theory; to experiment with neural nets.

Specification:

In addition to the programming project for this assignment you should look at the following problems out of the book: 13.6, 13.8, 13.18. For this homework you will probably want to make use of this face training set. Your goal in this assignment is to write a neural network program that can be used to distinguish between the happy, sad, and amazed faces I got you to draw a couple days ago. Your program must be written in Java, and will be run from the command line with the command:

java Hw4

At this point your program should enter training mode. It should look in the current directory for files to train on. These files will have names: h1.bmp, h2.bmp, h3.bmp, ...; s1.bmp, s2.bmp, s3.bmp, ...; a1.bmp, a2.bmp, a3.bmp, ... Names beginning with `h' are supposed to be happy faces, those beginning with `s' are supposed to be sad faces, and those beginning with `a' are supposed to be amazed faces. As an axample the zip file above contains 13 faces of each type you could try to train on. Your program should cycle through each file of the give type and train according to one of the neural net algorithms presented in class or found in Chapter 20 of the book. After completing training mode, your program should look for the files test1.bmp, test2.bmp, test3.bmp, ... It should read each one, apply it as an input into the neural net and based on the output of the net write on one line whether the face in the test file was happy, sad or amazed. For example, if there were 5 test files the output of your program might look like:

sad
happy
happy
sad
amazed

As usual 8 points of this assignment are for getting your program to do the above so that it can participate in a competition. Your score in the competition will be determined in the following manner: the program that identifies the most faces correctly will receive 7 points. For the remaining programs each face the winning program identifies that your program fails to identify will reduce your score from 7 by half a point. As you can guess you will be tested on at least 14 faces.

To do this homework it is useful to know a little about the structure of the bmp files your program is supposed to categorize, so I will now briefly summarize this before giving the point breakdown for the assignment. Basically, a bmp file consists of four parts: the header, the info header, the palette information, and the image data. The header is fourteen bytes long, the first two bytes are the letter B and M, the next four are the size of the file low order byte first, then four reserved bytes, followed by a four byte number low order byte first saying the offset to the start of the image data. The info header has information about the kind of bitmap file this is, containing information such as the bitmap's width and height as well as bit depth. The width and height are stored respectively four and eight bytes into the infoheader (18 and 22 bytes into the file ) and are 4 bytes each low order byte first. For this project the width and height will always be 100 (64 in hex if you looking at the file in textedit or a hex editor). At fourteen bytes into the infoheader (28 into file) you have the bit depth which is a two byte number low order first. For this assignment all files are depth 1. The info header is 40 bytes long total. So 54 bytes into the file one begins the color palette. The first three bytes of this are the b,g,r color value of a 0 bit in the image data. This is followed by one unused alpha value byte. Then next three bytes are the b, g, r values of a 1 bit in the image data followed again by one unused byte. For our files these will be 00 00 00 (black) 00 (alpha) and FF FF FF (white) 00 (alpha) respectively. Finally, we get the image data 62 bytes into the file. Images are stored left to right with the last row given first. Since the bit depth for our images is always 1, we will have 1 bit for each pixel. Rows however must be a mutliple of sizeof(int), that is, multiples of 4 bytes. So a row in our file will be 128bits = 16 bytes (or 4 int's) long. The last 28 bits of each row will always be zero. Since the image is 100 pixels tall the image data will always be 1600 bytes long. The total file length will thus always be 1662 bytes long. That's it for bmp files as far as we're concerned.

Point Breakdown

Departmental coding guidelines for Java followed 1pt
Reads each file of training set 2pts
Trains according to one of the algorithms mentioned in class or chapter 20 3pts
Evaluates test inputs correctly 2pts
Output of correct format 2pts
Your programs performance in the competition.5pts
Total15pts